package com.example.component

import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.component.a_activity.AFirstActivity
import com.example.component.b_fragment.container_change_qualifier.BAActivity
import com.example.component.c_broadcast.CActivity
import com.example.component.d_content_provider.DActivity
import com.example.component.databinding.ActivityMainBinding
import com.example.component.handler.HandlerActivity
import com.example.component.service.EAActivity
import com.example.component.util.launchActivity
import com.example.component.view.ViewActivity

class MainActivity : AppCompatActivity() {
    private lateinit var binding : ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityMainBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)
        ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        initButtons()
    }

    private fun initButtons() {
        findViewById<Button>(R.id.activity).setOnClickListener {
            launchActivity<AFirstActivity>()
        }
        findViewById<Button>(R.id.fragment).setOnClickListener {
            launchActivity<BAActivity>()
        }
        findViewById<Button>(R.id.broadcast).setOnClickListener {
            launchActivity<CActivity>()
        }
        findViewById<Button>(R.id.content_provider).setOnClickListener {
            launchActivity<DActivity>()
        }
        findViewById<Button>(R.id.handler).setOnClickListener {
            launchActivity<HandlerActivity>()
        }
        findViewById<Button>(R.id.service).setOnClickListener {
            launchActivity<EAActivity>()
        }
        binding.viewBtn.setOnClickListener {
            launchActivity<ViewActivity>()
        }
    }
}